package com.questions.helper.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class LegalknowledgeSQLiteOpenHelper extends SQLiteOpenHelper {
    private static final String name = "questions.db";
    private static final Integer version = 1;
    public static String tableQuestionsName = "questions";

    public static String tableAnswerName = "answer";
    Context context;
    public LegalknowledgeSQLiteOpenHelper(@Nullable Context context) {
        super(context, name, null, version);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
       // 执行sql
        db.execSQL("DROP TABLE IF EXISTS " + tableQuestionsName + ";");
        db.execSQL("create table "+tableQuestionsName+"(id integer primary key autoincrement,title_text text,questions_type text,answers_sort text);");
        // 执行sql
        db.execSQL("DROP TABLE IF EXISTS " + tableAnswerName + ";");
        db.execSQL("create table "+tableAnswerName+"(id integer primary key autoincrement,questions_id integer,title_text text,answers_sort text,answers_order intege,answers_correct intege);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.setVersion(newVersion);
    }


    public void deleteDabe(){
        this.context.deleteDatabase(name);
    }


}
